<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/widgets/qscrollarea.cpp -->
<head>
  <title>Qt 4.3: QScrollArea Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QScrollArea Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QScrollArea class provides a scrolling view onto another widget. <a href="#details">More...</a></p>
<pre> #include &lt;QScrollArea&gt;</pre><p>Inherits <a href="qabstractscrollarea.html">QAbstractScrollArea</a>.</p>
<ul>
<li><a href="qscrollarea-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<ul>
<li><div class="fn"/><b><a href="qscrollarea.html#alignment-prop">alignment</a></b> : Qt::Alignment</li>
<li><div class="fn"/><b><a href="qscrollarea.html#widgetResizable-prop">widgetResizable</a></b> : bool</li>
</ul>
<ul>
<li><div class="fn"/>2 properties inherited from <a href="qabstractscrollarea.html#properties">QAbstractScrollArea</a></li>
<li><div class="fn"/>6 properties inherited from <a href="qframe.html#properties">QFrame</a></li>
<li><div class="fn"/>56 properties inherited from <a href="qwidget.html#properties">QWidget</a></li>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qscrollarea.html#QScrollArea">QScrollArea</a></b> ( QWidget * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qscrollarea.html#dtor.QScrollArea">~QScrollArea</a></b> ()</li>
<li><div class="fn"/>Qt::Alignment <b><a href="qscrollarea.html#alignment-prop">alignment</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qscrollarea.html#ensureVisible">ensureVisible</a></b> ( int <i>x</i>, int <i>y</i>, int <i>xmargin</i> = 50, int <i>ymargin</i> = 50 )</li>
<li><div class="fn"/>void <b><a href="qscrollarea.html#ensureWidgetVisible">ensureWidgetVisible</a></b> ( QWidget * <i>childWidget</i>, int <i>xmargin</i> = 50, int <i>ymargin</i> = 50 )</li>
<li><div class="fn"/>void <b><a href="qscrollarea.html#alignment-prop">setAlignment</a></b> ( Qt::Alignment )</li>
<li><div class="fn"/>void <b><a href="qscrollarea.html#setWidget">setWidget</a></b> ( QWidget * <i>widget</i> )</li>
<li><div class="fn"/>void <b><a href="qscrollarea.html#widgetResizable-prop">setWidgetResizable</a></b> ( bool <i>resizable</i> )</li>
<li><div class="fn"/>QWidget * <b><a href="qscrollarea.html#takeWidget">takeWidget</a></b> ()</li>
<li><div class="fn"/>QWidget * <b><a href="qscrollarea.html#widget">widget</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qscrollarea.html#widgetResizable-prop">widgetResizable</a></b> () const</li>
</ul>
<ul>
<li><div class="fn"/>15 public functions inherited from <a href="qabstractscrollarea.html#public-functions">QAbstractScrollArea</a></li>
<li><div class="fn"/>13 public functions inherited from <a href="qframe.html#public-functions">QFrame</a></li>
<li><div class="fn"/>201 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
<li><div class="fn"/>12 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>19 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"/>16 protected functions inherited from <a href="qabstractscrollarea.html#protected-functions">QAbstractScrollArea</a></li>
<li><div class="fn"/>38 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
<li><div class="fn"/>1 protected function inherited from <a href="qpaintdevice.html#protected-functions">QPaintDevice</a></li>
<li><div class="fn"/>1 protected slot inherited from <a href="qabstractscrollarea.html#protected-slots">QAbstractScrollArea</a></li>
<li><div class="fn"/>1 protected slot inherited from <a href="qwidget.html#protected-slots">QWidget</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QScrollArea class provides a scrolling view onto another widget.</p>
<p>A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed. The child widget must be specified with <a href="qscrollarea.html#setWidget">setWidget</a>(). For example:</p>
<pre> QLabel *imageLabel = new QLabel;
 QImage image(&quot;happyguy.png&quot;);
 imageLabel-&gt;setPixmap(QPixmap::fromImage(image));

 scrollArea = new QScrollArea;
 scrollArea-&gt;setBackgroundRole(QPalette::Dark);
 scrollArea-&gt;setWidget(imageLabel);</pre>
<p>The code above creates a scroll area (shown in the images below) containing an image label. When scaling the image, the scroll area can provide the necessary scroll bars:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<tr valign="top" class="odd"><td><img src="images/qscrollarea-noscrollbars.png" /></td><td><img src="images/qscrollarea-onescrollbar.png" /></td><td><img src="images/qscrollarea-twoscrollbars.png" /></td></tr>
</table></p>
<p>The scroll bars appearance depends on the currently set <a href="qt.html#ScrollBarPolicy-enum">scroll bar policies</a>. You can control the appearance of the scroll bars using the inherited functionality from <a href="qabstractscrollarea.html">QAbstractScrollArea</a>.</p>
<p>For example, you can set the <a href="qabstractscrollarea.html#horizontalScrollBarPolicy-prop">QAbstractScrollArea::horizontalScrollBarPolicy</a> and <a href="qabstractscrollarea.html#verticalScrollBarPolicy-prop">QAbstractScrollArea::verticalScrollBarPolicy</a> properties. Or if you want the scroll bars to adjust dynamically when the contents of the scroll area changes, you can use the <a href="qabstractscrollarea.html#horizontalScrollBar">horizontalScrollBar()</a> and <a href="qabstractscrollarea.html#verticalScrollBar">verticalScrollBar()</a> functions (which enable you to access the scroll bars) and set the scroll bars' values whenever the scroll area's contents change, using the <a href="qabstractslider.html#value-prop">QScrollBar::setValue</a>() function.</p>
<p>You can retrieve the child widget using the <a href="qscrollarea.html#widget">widget</a>() function. The view can be made to be resizable with the <a href="qscrollarea.html#widgetResizable-prop">setWidgetResizable</a>() function. The alignment of the widget can be specified with <a href="qscrollarea.html#alignment-prop">setAlignment</a>().</p>
<p>When using a scroll area to display the contents of a custom widget, it is important to ensure that the <a href="qwidget.html#sizeHint-prop">size hint</a> of the child widget is set to a suitable value. If a standard <a href="qwidget.html">QWidget</a> is used for the child widget, it may be necessary to call <a href="qwidget.html#minimumSize-prop">QWidget::setMinimumSize</a>() to ensure that the contents of the widget are shown correctly within the scroll area.</p>
<p>Two convenience functions <a href="qscrollarea.html#ensureVisible">ensureVisible</a>() and <a href="qscrollarea.html#ensureWidgetVisible">ensureWidgetVisible</a>() ensure a certain region of the contents is visible inside the viewport, by scrolling the contents if necessary.</p>
<p>For a complete example using the QScrollArea class, see the <a href="widgets-imageviewer.html">Image Viewer</a> example. The example shows how to combine <a href="qlabel.html">QLabel</a> and QScrollArea to display an image.</p>
<p>See also <a href="qabstractscrollarea.html">QAbstractScrollArea</a>, <a href="qscrollbar.html">QScrollBar</a>, and <a href="widgets-imageviewer.html">Image Viewer Example</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="alignment-prop"></a>alignment : <a href="qt.html#AlignmentFlag-enum">Qt::Alignment</a></h3>
<p>This property holds the alignment of the scroll area's widget.</p>
<p>By default, the widget stays rooted to the top-left corner of the scroll area.</p>
<p>This property was introduced in Qt 4.2.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>Qt::Alignment alignment () const</b></li>
<li><div class="fn"/><b>void setAlignment ( Qt::Alignment )</b></li>
</ul>
<h3 class="fn"><a name="widgetResizable-prop"></a>widgetResizable : bool</h3>
<p>This property holds whether the scroll area should resize the view widget.</p>
<p>If this property is set to false (the default), the scroll area honors the size of its widget. Regardless of this property, you can programmatically resize the widget using <a href="qscrollarea.html#widget">widget</a>()-&gt;<a href="qwidget.html#size-prop">resize</a>(), and the scroll area will automatically adjust itself to the new size.</p>
<p>If this property is set to true, the scroll area will automatically resize the widget in order to avoid scroll bars where they can be avoided, or to take advantage of extra space.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>bool widgetResizable () const</b></li>
<li><div class="fn"/><b>void setWidgetResizable ( bool <i>resizable</i> )</b></li>
</ul>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QScrollArea"></a>QScrollArea::QScrollArea ( <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0 )</h3>
<p>Constructs an empty scroll area with the given <i>parent</i>.</p>
<p>See also <a href="qscrollarea.html#setWidget">setWidget</a>().</p>
<h3 class="fn"><a name="dtor.QScrollArea"></a>QScrollArea::~QScrollArea ()</h3>
<p>Destroys the scroll area and its child widget.</p>
<p>See also <a href="qscrollarea.html#setWidget">setWidget</a>().</p>
<h3 class="fn"><a name="ensureVisible"></a>void QScrollArea::ensureVisible ( int <i>x</i>, int <i>y</i>, int <i>xmargin</i> = 50, int <i>ymargin</i> = 50 )</h3>
<p>Scrolls the contents of the scroll area so that the point (<i>x</i>, <i>y</i>) is visible inside the region of the viewport with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.</p>
<h3 class="fn"><a name="ensureWidgetVisible"></a>void QScrollArea::ensureWidgetVisible ( <a href="qwidget.html">QWidget</a> * <i>childWidget</i>, int <i>xmargin</i> = 50, int <i>ymargin</i> = 50 )</h3>
<p>Scrolls the contents of the scroll area so that the <i>childWidget</i> of <a href="qscrollarea.html#widget">QScrollArea::widget</a>() is visible inside the viewport with margins specified in pixels by <i>xmargin</i> and <i>ymargin</i>. If the specified point cannot be reached, the contents are scrolled to the nearest valid position. The default value for both margins is 50 pixels.</p>
<p>This function was introduced in Qt 4.2.</p>
<h3 class="fn"><a name="setWidget"></a>void QScrollArea::setWidget ( <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
<p>Sets the scroll area's <i>widget</i>.</p>
<p>The <i>widget</i> becomes a child of the scroll area, and will be destroyed when the scroll area is deleted or when a new widget is set.</p>
<p>Note that if the scroll area is visible when the <i>widget</i> is added, you must <a href="qwidget.html#show">show()</a> it explicitly.</p>
<p>See also <a href="qscrollarea.html#widget">widget</a>().</p>
<h3 class="fn"><a name="takeWidget"></a><a href="qwidget.html">QWidget</a> * QScrollArea::takeWidget ()</h3>
<p>Removes the scroll area's widget, and passes ownership of the widget to the caller.</p>
<p>See also <a href="qscrollarea.html#widget">widget</a>().</p>
<h3 class="fn"><a name="widget"></a><a href="qwidget.html">QWidget</a> * QScrollArea::widget () const</h3>
<p>Returns the scroll area's widget, or 0 if there is none.</p>
<p>See also <a href="qscrollarea.html#setWidget">setWidget</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
